<template>
<x-main>
  <view class="order">
    <x-search :statusOption="ORDER.STATUS" @search="onSearch"></x-search>
    <view style="padding-top: 200rpx">
      <x-empty :show="$emptyArray(records)"></x-empty>
      <template v-for="(data, index) in records" >
        <x-item :data="data"></x-item>
      </template>
    </view>
  </view>
</x-main>
</template>

<script setup>
import {reactive} from "vue";
import XSearch from '@/components/logic/search'
import XItem from '@/components/logic/order/item'
import orderStore from '@/stores/modules/order';
import {onLoad, onReachBottom, onShow} from "@dcloudio/uni-app";
import {storeToRefs} from "pinia";
import {Helper} from "core";

const OrderStore = orderStore();
const {pageNo, pageSize, total, condition, records} = storeToRefs(OrderStore);
onShow(() => {
  if(Helper.empty(condition.value.beginTime)) {
    let {start, end} = Helper.formatQueryDate("01");
    condition.value.beginTime = start;
    condition.value.endTime = end;
  }
  OrderStore.getList(1, pageSize.value, condition.value);
})

const onSearch = (condition) => {
  if(! Helper.empty(condition.keyword)) {
    condition.ownerPhone = condition.keyword;
  }

  if(! Helper.empty(condition.status)) {
    condition.orderState = condition.status;

  }
  delete condition.status;
  delete condition.keyword;
  OrderStore.getList(1, pageSize.value, condition);
}

onReachBottom(() => {
  OrderStore.getList(pageNo.value + 1, pageSize.value, condition.value);
})

</script>

<style scoped lang="less">
.order {

}
</style>
